﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cludg.Repository.Security
{
    using Domain.Users;

    public static class SecurityRepositoryHelper
    {
        public static User GetUserByEmail(this ISecurityRepository repository, string email)
        {
            return repository.AllUsers.FirstOrDefault(u => u.Email == email);
        }

        public static bool HasUserByEmail(this ISecurityRepository repository, string email)
        {
            return GetUserByEmail(repository, email) != null;
        }

        public static bool HasUserSecurityInfoByThirdPartyIdent(this ISecurityRepository repository, string ident)
        {
            return repository.GetUserSecurityInfoByThirPartyIdent(ident) != null;
        }

        public static bool HasUserSecurityInfoByName(this ISecurityRepository repository, string name)
        {
            return repository.GetUserSecurityInfoByName(name) != null;
        }

        public static bool HasUserSecurityInfoByEmail(this ISecurityRepository repository, string email)
        {
            return repository.GetUserSecurityInfoByEmail(email) != null;
        }

        public static void ChangeUserSecurityInfo(this ISecurityRepository repository, User user, UserSecurityInfo info)
        {
            repository.ChangeUserSecurityInfo(user.Id, info);
        }

        public static void SaveUser(this ISecurityRepository repository, User user)
        {
            repository.SaveUser(user.Id, user);
        }
    }
}
